using System;
using System.Collections.Generic;
using Akcedo.Framework.Infrastructure.ASPNet;
using FwkLight.Domain.Fetching;
using StructureMap;

namespace FwkLight.Application
{
  public class Task<T>
  {
    private RequestItemDictionary _requestItemDictionary = ObjectFactory.GetInstance<RequestItemDictionary>();
    private Type _taskTypeWaitingForFetchingConfig;

    public Task()
    {
      _taskTypeWaitingForFetchingConfig = typeof(T);
    }

    public void ShouldUseFetchingStrategy<T>()
    {
      IList<FetchingConfiguration> fetchingConfig =
        _requestItemDictionary.Get(ApplicationConstants.Request.FetchingConfigurationList);

      if (fetchingConfig == null)
        fetchingConfig = new List<FetchingConfiguration>();

      fetchingConfig.Add(new FetchingConfiguration(_taskTypeWaitingForFetchingConfig, typeof(T)));

      _requestItemDictionary.Add(ApplicationConstants.Request.FetchingConfigurationList, fetchingConfig);
    }
  }
}